﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Serialization;
using DAL.Entity;
using DAL.Persistencia;

namespace NewTierra.Pages.ashx
{
    /// <summary>
    /// Summary description for SearchTours
    /// </summary>
    public class SearchTours : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            ServicoDAL ftd = new ServicoDAL();

            var term = context.Request.QueryString["term"].ToString();
            var Cidade = context.Request.QueryString["param1"].ToString();

            context.Response.Clear();
            context.Response.ContentType = "application/json";

            List<S_Servicos> servicos = new List<S_Servicos>();

            if (!Cidade.Equals(""))
            {
                servicos = ftd.ListarTodosTor(term, new CidadeDAL().ObterPorNome(Cidade).CID_id);
            }
            else
            {
                servicos = ftd.ListarTodosTor(term);
            }

            List<string> lista = new List<string>();


            foreach (S_Servicos p in servicos)
            {
                lista.Add(p.Servicos_Nome);
            }

            var search = lista;

            JavaScriptSerializer jsSerializer = new JavaScriptSerializer();
            string json = jsSerializer.Serialize(search);
            context.Response.Write(json);
            context.Response.End();
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}